import React,{useEffect,useState} from 'react'
import axios from 'axios'
export default function MoviesList() {

 const [movieList,setMovieList]=useState([])
  //第2个参数是一个[]数组，模拟componentDidMount
  useEffect(()=>{
    console.log('-------------');
    getMovieListApi()
  },[])
  const getMovieListApi=()=>{
    axios({
        url:'https://www.fastmock.site/mock/4441a79ad5f884f83b784cf4c588bdb6/movies/getHotMovies',
        method:'GET'
    }).then(response=>{
        console.log(response.data.movies);
        setMovieList(response.data.movies)
    })
 
  }
  return (
    <div>
        <ul>
            {
                movieList.map(item=><li key={item.id}>{item.title}</li>)
            }
        </ul>
    </div>
  )
}
